package com.example.demo_mysql_mybatisplus.util.responce.results.filler.demo;

import com.example.demo_mysql_mybatisplus.util.responce.results.filler.FillResponces;
import com.example.demo_mysql_mybatisplus.util.responce.results.filler.core.FillResponce;
import com.example.demo_mysql_mybatisplus.util.responce.results.filler.demo.entitys.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

@RestController
@RequestMapping("responce/filler")
public class FillerController {

    @GetMapping("demo_1")
    @FillResponces({
            @FillResponce(target = AAA.class , by = "name", fillFields = "code,age" , useMethod = "getAAA"),
            @FillResponce(target = DDD.class , fillFields = "name,code" , useMethod = "getDDD"),
            @FillResponce(target = CCC.class , fillFields = "name,code" , useMethod = "getCCC"),
            @FillResponce(target = EEE.class , fillFields = "name,code,age,birthday" , useMethod = "getEEE"),
    })
    public Object demo_1(){
        return demoData2() ;
    }


    @GetMapping("demo_2")
    @FillResponces({
            @FillResponce(target = AAA.class , by = "id", fillFields = "name,code" , useMethod = "getAAA"),
            @FillResponce(target = DDD.class , fillFields = "code" , useMethod = "getDDD"),
            @FillResponce(target = CCC.class , fillFields = "name,age" , useMethod = "getCCC"),
            @FillResponce(target = EEE.class , fillFields = "name,code,age,birthday" , useMethod = "getEEE"),
    })
    public Object demo_2(){
        return Arrays.asList(demoData1(),demoData2()) ;
    }


    @GetMapping("demo_3")
    @FillResponces({
            @FillResponce(target = AAA.class , by = "code", defaultFields = true, useMethod = "getAAA"),
            @FillResponce(target = DDD.class , fillFields = "code", useMethod = "getDDD"),
            @FillResponce(target = CCC.class , defaultFields = true, useMethod = "getCCC"),
            @FillResponce(target = EEE.class , fillFields = "age,birthday", useMethod = "getEEE"),
            @FillResponce(target = FFF.class , allFields = true, useMethod = "getFFF")
    })
    public Object demo_3(){
        return demoData2() ;
    }




    private AAA demoData1(){
        AAA responce = new AAA();
        responce.setId(11) ;
        responce.setName("name_a1") ;
        responce.setCode("code_a1") ;

        responce.setBbb(new BBB());
        responce.getBbb().setId(21) ;
        responce.getBbb().setDdd(new DDD());
        responce.getBbb().getDdd().setId(41) ;

        responce.setCccs(new ArrayList<>());

        CCC ccc1 = new CCC().setId(31) ;
        ccc1.setEees(new HashSet<>());
        ccc1.getEees().add( new EEE().setId(51) );
        ccc1.getEees().add( new EEE().setId(52) );
        responce.getCccs().add(ccc1);

        return  responce ;
    }

    private AAA demoData2(){
        AAA responce = demoData1();

        CCC ccc2 = new CCC().setId(32) ;
        ccc2.setEees(new HashSet<>());
        ccc2.getEees().add( new EEE().setId(53).setFff(new FFF().setId(61L))  );
        ccc2.getEees().add( new EEE().setId(54)  );
        responce.getCccs().add(ccc2);
        return  responce ;
    }
}

